<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
    <title>成绩管理</title>
    <link rel="stylesheet"
          href="${pageContext.request.contextPath}/static/css/bootstrap.min.css"
          type="text/css">
    <!-- 引入jQuery和Bootstrap的日期选择器插件 -->
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <link rel="stylesheet"
          href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/css/bootstrap-datepicker.min.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js"></script>
</head>
<body>

<%@ include file="index.jsp" %>
<br>
<div class="container col-md-5">
    <div class="card">
        <c:if test="${grade != null}">
        <form action="<%=request.getContextPath()%>/grade/update" method="post">
            </c:if>
            <c:if test="${grade == null}">
            <form action="<%=request.getContextPath()%>/grade/insert" method="post">
                </c:if>
                <caption>
                    <h2>
                        <c:if test="${grade != null}">
                            编辑用户
                        </c:if>
                        <c:if test="${grade == null}">
                            添加新用户
                        </c:if>
                    </h2>
                </caption>

                <c:if test="${grade != null}">
                    <input type="hidden" name="gradeId" value="<c:out value='${grade.gradeId}' />"/>
                </c:if>
                <fieldset class="form-group">
                    <label>学生姓名</label>
                    <select class="form-control" name="studentName" required="required">
                        <option value="" disabled selected>请选择学生姓名</option>
                        <c:forEach var="name" items="${stuNames}">
                            <option value="${name}" ${grade != null && grade.studentName == name ? 'selected' : ''}>${name}</option>
                        </c:forEach>
                    </select>
                </fieldset>
                <fieldset class="form-group">
                    <label>课程名</label>
                    <select class="form-control" name="courseName" required="required">
                        <option value="" disabled selected>请选择课程名</option>
                        <c:forEach var="name" items="${courseNames}">
                            <option value="${name}" ${grade != null && grade.courseName == name ? 'selected' : ''}>${name}</option>
                        </c:forEach>
                    </select>
                </fieldset>
                <fieldset class="form-group">
                    <label>成绩</label>
                    <input type="number"
                           value="<c:out value='${grade.score}' />"
                           class="form-control"
                           name="score"
                           min="0"
                           max="100"
                           step="0.1"
                           required="required">
                </fieldset>

                <fieldset class="form-group">
                    <label>学期</label>
                    <select class="form-control" name="term" required="required">
                        <option value="" disabled selected>请选择学期</option>
                        <option value="2022-2022秋" ${grade.term == '2022-2022秋' ? 'selected' : ''}>2022-2022年秋</option>
                        <option value="2022-2023春" ${grade.term == '2022-2023春' ? 'selected' : ''}>2022-2023年春</option>
                        <option value="2023-2023秋" ${grade.term == '2023-2023秋' ? 'selected' : ''}>2023-2023年秋</option>
                        <option value="2023-2024春" ${grade.term == '2023-2024春' ? 'selected' : ''}>2023-2024年春</option>
                        <option value="2024-2024秋" ${grade.term == '2024-2024秋' ? 'selected' : ''}>2024-2024年秋</option>
                        <option value="2024-2025春" ${grade.term == '2024-2025春' ? 'selected' : ''}>2024-2025年春</option>
                        <option value="2025-2025秋" ${grade.term == '2025-2025秋' ? 'selected' : ''}>2025-2025年秋</option>
                        <option value="2025-2026春" ${grade.term == '2025-2026春' ? 'selected' : ''}>2025-2026年春</option>
                    </select>
                </fieldset>
                <fieldset class="form-group">
                    <label>考试日期</label>
                    <input type="text" id="examDate" class="form-control datepicker" name="examDate"
                           value="<c:out value='${grade.examDate}' />" required="required">
                </fieldset>
                <!-- 初始化日期选择器 -->
                <script>
                    $(function () {
                        $('#examDate').datepicker({
                            format: 'yyyy-mm-dd',
                            autoclose: true,
                            todayHighlight: true
                        });
                    });
                </script>
                <button type="submit" class="btn btn-success">保存</button>
            </form>
    </div>
</div>
</body>
</html>